package server.xml;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WebXml {
    //会话超时时间,单位为分钟
    private int sessionTimeout = 30;

    private List<String> welcomeFileList = new ArrayList<>();

    private List<ServletDef> servletDefs = new ArrayList<>();
    private List<ServletMap> servletMappings = new ArrayList<>();

    private List<FilterDef> filterDefs = new ArrayList<>();
    private List<FilterMap> filterMappings = new ArrayList<>();

    private List<String> listeners = new ArrayList<>();

    private Map<Integer, String> errorPages = new HashMap<>();

    public int getSessionTimeout() {
        return sessionTimeout;
    }

    public List<String> getWelcomeFileList() {
        return welcomeFileList;
    }

    public List<ServletDef> getServletDefs() {
        return servletDefs;
    }

    public List<ServletMap> getServletMappings() {
        return servletMappings;
    }

    public List<FilterDef> getFilterDefs() {
        return filterDefs;
    }

    public List<FilterMap> getFilterMappings() {
        return filterMappings;
    }

    public List<String> getListeners() {
        return listeners;
    }

    public Map<Integer, String> getErrorPages() {
        return errorPages;
    }

    public void setSessionTimeout(int sessionTimeout) {
        this.sessionTimeout = sessionTimeout;
    }

    public void addWelcomeFile(String welcomeFile) {
        welcomeFileList.add(welcomeFile);
    }

    public void addServletDef(ServletDef servletDef) {
        servletDefs.add(servletDef);
    }

    public void addServletMapping(ServletMap servletMapping) {
        servletMappings.add(servletMapping);
    }

    public void addFilterDef(FilterDef filterDef) {
        filterDefs.add(filterDef);
    }

    public void addFilterMappings(FilterMap filterMapping) {
        filterMappings.add(filterMapping);
    }

    public void addListener(String listener) {
        listeners.add(listener);
    }

    public void addErrorPage(int statusCode, String location) {
        errorPages.put(statusCode, location);
    }

    @Override
    public String toString() {
        return "WebXml{" +
                "sessionTimeout=" + sessionTimeout +
                ", welcomeFileList=" + welcomeFileList +
                ", servletDefs=" + servletDefs +
                ", servletMappings=" + servletMappings +
                ", filterDefs=" + filterDefs +
                ", filterMappings=" + filterMappings +
                ", listeners=" + listeners +
                ", errorPages=" + errorPages +
                '}';
    }
}
